
/**
 * 通过remoteurl加载模态框添加界面
 * @param href
 */
function modalView(href) {
	common_modals.showRemoteModal(href);
}

/**
 * 选择一项数据后 通过remoteurl加载模态框添加界面
 * @param href
 */
function modalViewAfterSelect(href) {
	if (common_jqgrid.getSelectedIds()==null || common_jqgrid.getSelectedIds().length==0) {
		common_modals.swalWarning("请选择需要操作的数据！","");
	} else if (common_jqgrid.getSelectedIds().length > 1) {
		common_modals.swalWarning("请最多选择一项操作的数据！","");
	} else {
		href = utils.changeURLArg(href,'id',common_jqgrid.getSelectedIds()[0]);
		modalView(href);
	}
}

/**
 * ajax 删除表格数据
 * @param href
 */
function ajaxGridDelete(href,confirmButtonCallback) {
	if (common_jqgrid.getSelectedIds()==null || common_jqgrid.getSelectedIds().length==0) {
		common_modals.swalWarning("请选择需要操作的数据！","");
	} else {
		var param = {
				ids:common_jqgrid.getSelectedIds()
			};
		common_ajax.ajaxFuncConfirm("确认删除吗？", href,param,"json",
			function(result){
				common_modals.swalAlertByStatusCode(result,function(){
					if (confirmButtonCallback != null) {
						confirmButtonCallback();
					}
		    });
		});
		
	}
}

/**
 * ajax 表单提交
 * @param url
 */
function ajaxFormSubmit(url,confirmButtonCallback){
	if (!$("#ajaxForm").valid()) {
		return;
	}
	var result = common_ajax.ajaxFunc(url,$("#ajaxForm").serialize(),"json");
	common_modals.swalAlertByStatusCode(result,function(){
		if (confirmButtonCallback != null) {
			confirmButtonCallback();
		}
    });
	
}

/**
 * ajax 提交
 * @param url
 */
function ajaxSubmit(url,confirmButtonCallback){
	var result = common_ajax.ajaxFunc(url,"","json");
	common_modals.swalAlertByStatusCode(result,function(){
		if (confirmButtonCallback != null) {
			confirmButtonCallback();
		}
    });
	
}

/**
 * 用户点击确认后ajax提交
 * @param href
 * @param params
 * @param confirmButtonCallback
 */
function ajaxDo(href,params,confirmButtonCallback) {
	common_ajax.ajaxFunc(href,params,"json",function(result){
		common_modals.swalAlertByStatusCode(result,function(){
			if (confirmButtonCallback != null) {
				confirmButtonCallback();
			}
        });
	});
}

/**
 * 用户点击确认后ajax提交
 * @param href
 * @param params
 * @param confirmButtonCallback
 */
function ajaxDialogCheck(href,params,confirmButtonCallback) {
	common_ajax.ajaxFuncConfirm("", href,params,"json",function(result){
		common_modals.swalAlertByStatusCode(result,function(){
			if (confirmButtonCallback != null) {
				confirmButtonCallback();
			}
        });
	});
}

/**
 * 用户点击确认后ajax提交
 * @param href
 * @param params
 * @param confirmButtonCallback
 */
function ajaxConfirm(message, href,params,confirmButtonCallback) {
	common_ajax.ajaxFuncConfirm(message, href,params,"json",function(result){
		common_modals.swalAlertByStatusCode(result,function(){
			if (confirmButtonCallback != null) {
				confirmButtonCallback();
			}
        });
	});
}

/**
 * 用户点击确认后ajax提交
 * @param href
 * @param params
 * @param confirmButtonCallback
 */
function ajaxLayuiConfirm(message, href,params,confirmButtonCallback) {
	//询问框
	layer.confirm(message, {
	  btn: ['确定','取消'] //按钮
	}, function(){
		common_ajax.ajaxFunc(href,params,"json",function(result){
			common_modals.swalAlertByStatusCode(result,function(){
				if (confirmButtonCallback != null) {
					confirmButtonCallback();
				}
	        });
		});
	}, function(){
	  layer.msg('也可以这样', {
	    time: 2000, //20s后自动关闭
	    btn: ['明白了', '知道了']
	  });
	});
	
}

function ajaxOrderSave(url,params,confirmButtonCallback) {
	var result = common_ajax.ajaxFunc(url,params,"json");
	common_modals.swalAlertByStatusCode(result,function(){
		if (confirmButtonCallback != null) {
			confirmButtonCallback();
		}
    });
}
